public class CanvasBottom extends Canvas {

  Node trunkWorld;
  Polygon window;
  public CanvasBottom(PVector origin, int h, int w, color backgroundColor, Node trunkWorld, Polygon window) {
    super(origin, h, w, backgroundColor);
    this.trunkWorld = trunkWorld;
    this.window = window;
  }

  @Override
    public void draw() {
    pg.beginDraw();
    pg.background(backgroundColor);
    ArrayList<Polygon> windowView = new ArrayList<Polygon>();
    for (Polygon p : trunkWorld.getFigures()) {
      p.draw(pg);
      ArrayList<Polygon> cut = p.cut(window);
      windowView.addAll(cut);
    }
    for (int i=0; i < windowView.size(); i++) {
      windowView.get(i).setFgColor(color(255, 204, 0));
      windowView.get(i).draw(pg);
    }
    window.draw(pg);
    //Lets draw the normals of the window
//    ArrayList<PVector> n = window.getNormals();
//    for (int i=0; i < n.size(); i++) {
//      Polygon tmp = new Polygon(color(255, 204, 0));
//      tmp.addPoint(window.getPoint(i));
//      PVector t = PVector.add(window.getPoint(i), PVector.mult(n.get(i), 10.0f));
//      tmp.addPoint(t);
//      tmp.draw(pg);
//    }
    pg.endDraw();

    image(pg, origin.x, origin.y);
  }
}

